//
//  UIImageView+SDAnimation.m
//  B2C
//
//  Created by xiaowu on 2017/9/1.
//  Copyright © 2017年 lixiaolong. All rights reserved.
//

#import "UIImageView+SDAnimation.h"

@implementation UIImageView (SDAnimation)

- (void)animationWithImageURL:(NSString *)url placeholderImage:(UIImage *)image {
    
    __weak typeof(self) weakSelf = self;
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:image completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (image && (cacheType != SDImageCacheTypeMemory)) {
            [weakSelf animationForGradual];
        }
    }];
}

- (void)animationForGradual {
    __weak typeof(self) weakSelf = self;
    self.alpha = 0.7;
    [UIView animateWithDuration:0.95 animations:^{
        weakSelf.alpha = 1.0;
    } completion:^(BOOL finished) {
        weakSelf.alpha = 1.0;
    }];
}

@end
